package com.example.demo.app.validate;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SexValidator implements ConstraintValidator<SexValid, Integer>{

	@Override
	public void initialize(SexValid constraintAnnotation) {
		log.info("my validator init");
	}

	@Override
	public boolean isValid(Integer value, ConstraintValidatorContext context) {
		boolean isValid = (value == 0 || value == 1);
		System.out.println(isValid);
		 if (!isValid) {
			 context.disableDefaultConstraintViolation();
			 context.buildConstraintViolationWithTemplate("sex data error")
			 .addPropertyNode("userName")
	         .addConstraintViolation();
	        } 
		return isValid;
	}
}
